<template>
  <el-container>
    <el-header>
      <h2 @click="clickLogo">坚果仓库管理系统</h2>
      <div class="right-user">
        <el-dropdown @command="clickCommand">
          <span>
            {{ user.username.username }}<i class="el-icon-user"></i>
          </span>
          <el-dropdown-menu>
            <el-dropdown-item icon="el-icon-close" command="back">安全退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          default-active="/index/home"
          class="el-menu-vertical-demo"
          router
        >
          <el-menu-item index="/index/home">
            <template slot="title">
              <i class="el-icon-house"></i>
              <span>首页</span>
            </template>
          </el-menu-item>
          <el-submenu
            :index="item.title"
            v-for="item in user.username.menus"
            :key="item.id"
            v-show="item.child.length != 0"
          >
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.title }}</span>
            </template>
            <el-menu-item
              :index="'/index' + ele.power"
              v-for="ele in item.child"
              :key="ele.pid"
              >{{ ele.pname }}</el-menu-item
            >
          </el-submenu>
          <!-- <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-s-operation"></i>
              <span>基本管理</span>
            </template>
            <el-menu-item index="/index/client">客户管理</el-menu-item>
            <el-menu-item index="/index/supply">供应商管理</el-menu-item>
            <el-menu-item index="/index/goods">商品管理</el-menu-item>
            <el-menu-item index="/index/store">仓库管理</el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-box"></i>
              <span>仓库管理</span>
            </template>
            <el-menu-item index="/index/put">入库</el-menu-item>
            <el-menu-item index="/index/out">出库</el-menu-item>
            <el-menu-item index="/index/stock">仓库详情</el-menu-item>
            
          </el-submenu> -->
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
export default {
  mounted() {
    console.log(this.user);
  },
  methods: {
    ...mapActions({
        "userAction":"login/userActions"
      }),
    clickLogo() {
      this.$router.push({path:'/index'})
    },
  clickCommand(command){
    if(command=='back'){
      this.userAction(null)
      this.$router.push({path:'/login'})
    }
  }
  },
  computed: {
    ...mapGetters({
      power: "login/power",
      user: "login/user",
    }),
  },
};
</script>

<style lang="less" scoped>
h2 {
  float: left;
  color: #555;
  cursor:pointer;
}
h2:hover {
  color: #aaa;
  text-shadow: 1px 1px 0 #aaa;
}
.right-user {
  height: 100%;
  line-height: 100%;
  /* text-align: center; */
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-right: 10%;
  .el-dropdown{
    cursor:pointer;
  }
  span {
    font-size: 20px;
    .el-icon-user {
      margin-left: 5px;
    }
  }
}
</style>
